package com.lixiangfeiyang.recycleritemhelperdemo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.lixiangfeiyang.recycleritemhelperdemo.databinding.ActivityMainBinding

class ImageActivity : AppCompatActivity() {

    var list = arrayListOf<Int>()
    private lateinit var adapter: ImageAdapter


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val viewBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(viewBinding.root)


        for (index in 1..10) {
            list.add(index)
        }

        //矩阵
        viewBinding.recyclerList.layoutManager = GridLayoutManager(this, 3)
        adapter = ImageAdapter(list)
        viewBinding.recyclerList.adapter = adapter

        val itemTouchHelper = GridItemTouchHelperUtil(adapter, viewBinding.deleteView, object : GridItemTouchHelperUtil.IsCanMoveCallBack {
            override fun itemCanMove(adapter: ImageAdapter, holder: RecyclerView.ViewHolder): Boolean {
                return adapter.list[holder.adapterPosition] != 10
            }

        }).init()

        itemTouchHelper.attachToRecyclerView(viewBinding.recyclerList)


    }
}